//
//  BaseNavigationController.m
//  ShopStore
//
//  Created by 东亨 on 2017/5/2.
//  Copyright © 2017年 lichao. All rights reserved.
//

#import "BaseNavigationController.h"
#import "RDVTabBarController.h"
//#import "LCEnrollmentViewController.h"
#import "LCBarView.h"

@interface BaseNavigationController ()<UIGestureRecognizerDelegate>
@property (strong,nonatomic)LCBarView *barView;
@end

@implementation BaseNavigationController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSInteger count =  self.navigationController.childViewControllers.count;
    if (count > 1) {
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
        self.leftBtn.hidden = NO;
        self.leftImgView.hidden = NO;
    }
    else
    {
        [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
        self.leftBtn.hidden = YES;
        self.leftImgView.hidden = YES;
    }
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tabBarController.edgesForExtendedLayout = UIRectEdgeNone;
    _topView = ({
        UIView *view = [[UIView alloc]init];
        [self.view addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.view);
            make.height.mas_equalTo(64);
        }];
        view.backgroundColor = [UIColor colorWithHex:0x343434];
        view;
    });
//    _lineView = ({
//        UIView *view = [[UIView alloc]init];
//        [_topView addSubview:view];
//        [view mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(_topView).offset(63);
//            make.left.right.equalTo(_topView);
//            make.height.mas_equalTo(1);
//        }];
//        view.backgroundColor = [UIColor colorWithHex:0xb2b2b2];
//        view;
//    });
    _titleLbl = ({
        UILabel *label = [[UILabel alloc]init];
        [_topView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.view.mas_centerX);
            make.top.mas_equalTo(31);
            make.size.mas_equalTo(CGSizeMake(200, 22));
        }];
        label.font = HYQIHEI_Regular(16);
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label;
    });
    _leftImgView = ({
        UIImageView  *imgView = [[UIImageView alloc]init];
        [self.view addSubview:imgView];
        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_topView).offset(10);
            make.top.equalTo(_topView).offset(33);
            make.size.mas_equalTo(CGSizeMake(10, 15));
        }];
        imgView.image = img(@"back");
        imgView;
    });
    _leftBtn = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [_topView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_topView).offset(0);
            make.top.equalTo(_topView).offset(22);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        [button addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        button;
    });
//    _rightImg = ({
//        UIImageView  *imgView = [[UIImageView alloc]init];
//        [self.view addSubview:imgView];
//        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.mas_equalTo(-10);
//            make.centerY.equalTo(_titleLbl);
//            make.size.mas_equalTo(CGSizeMake(22, 5));
//        }];
//        imgView;
//    });
//      _rightImg.image = img(@"path@2x.png");
    
//    _rightBtn = ({
//        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//        [self.view addSubview:button];
//        [button mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.mas_equalTo(-5);
//            make.centerY.equalTo(_titleLbl);
//            make.size.mas_equalTo(CGSizeMake(40, 40));
//        }];
//        [button addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//        button;
//    });
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 判断导航控制器是否只有2个子控制器，如果只有2个子控制器，肯定是根控制器
    NSInteger count =  self.navigationController.childViewControllers.count;
    if (count == 1) {
        return NO;
    }
    return YES;
}
-(void)setBarTitle:(NSString *)titleString
{
    _titleLbl.text = titleString;
}
//左边按钮点击方法
- (void)leftBtnClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
//右边按钮点击方法
//- (void)rightBtnClick:(UIButton *)sender
//{
//    _rightBtn.enabled = NO;
//    _barView = [[LCBarView alloc]init];
//    _barView.frame = CGRectMake(SCREEN_WIDTH-115, CGRectGetHeight(_topView.frame), CGRectGetWidth(_barView.frame), CGRectGetHeight(_barView.frame));
////    [UIView animateWithDuration:0.7 animations:^
////     {
////         [UIView setAnimationTransition:5 forView:_barView cache:YES];
////     } completion:^(BOOL finished)
////     {
////     }];
//    [self.view addSubview:_barView];
//    __weak LCBarView *weak = _barView;
//    __weak typeof(self) weakself = self;
//    [_barView setBtnClickBlock:^(NSInteger index)
//    {
//        switch (index)
//        {
//            case 1:
//            {
//                LCEnrollmentViewController *vc = [[LCEnrollmentViewController alloc]init];
//                [weakself.navigationController pushViewController:vc animated:YES];
//                break;
//            }
//            default:
//                break;
//        }
//        [weak removeFromSuperview];
//        weakself.rightBtn.enabled = YES;
//    }];
//}
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    [_barView removeFromSuperview];
//    _rightBtn.enabled = YES;
//}
@end
